package com.fulihui.wgj.admin.api.mass;

import com.fulihui.common.builder.web.JsonResultBuilder;
import com.fulihui.common.result.web.PageView;
import com.fulihui.common.result.web.Result;
import com.fulihui.wgj.admin.api.base.BaseController;
import com.fulihui.wgj.admin.api.mass.request.MassDataStatisDetailQueryRequest;
import com.fulihui.wgj.admin.api.mass.request.MassDataStatisQueryRequest;
import com.fulihui.wgj.admin.api.mass.vo.MassDataStatisDetailVO;
import com.fulihui.wgj.admin.api.mass.vo.MassDataStatisVO;
import com.fulihui.wgj.admin.integration.datastaits.MassDataStatisApiClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;
import java.util.Objects;

/**
 * @author: Levon
 * @date: 2018-08-01 13:55
 */
@RestController
@RequestMapping("/mass/data")
@Api(tags = "图文分析数据分析相关接口")
public class MassDataStatisController extends BaseController {

    @Autowired
    private MassDataStatisApiClient massDataStatisApiClient;


    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ApiOperation("图文分析数据列表")
    public Result<PageView<MassDataStatisVO>> queryPage(@RequestBody @Valid MassDataStatisQueryRequest request, BindingResult validResult,
                                                        HttpServletRequest servletRequest) {
        Result result = valid(validResult);
        if (Objects.nonNull(result)) {
            return result;
        }
        request.setAppId(getAppid(servletRequest));
        PageView<MassDataStatisVO> pageView = massDataStatisApiClient.queryMassDataStatisPage(request);
        return JsonResultBuilder.succ(pageView);
    }


    @PostMapping("/detail")
    @ApiOperation("图文分析数据详情")
    public Result<List<MassDataStatisDetailVO>> taglist(@RequestBody @Valid MassDataStatisDetailQueryRequest request, BindingResult validResult,
                                                        HttpServletRequest servletRequest) {
        Result result = valid(validResult);
        if (Objects.nonNull(result)) {
            return result;
        }
        request.setAppId(getAppid(servletRequest));
        List<MassDataStatisDetailVO> dataStatisDetailVOS = massDataStatisApiClient.queryMassDataDetail(request);
        return JsonResultBuilder.succ(dataStatisDetailVOS);
    }

}
